package com.resource.transactions.service.impl;


import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resource.transactions.config.AliyunConfig;
import com.resource.transactions.dao.RUserDao;
import com.resource.transactions.entities.RUser;
import com.resource.transactions.service.RUserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RUserServiceImpl extends ServiceImpl<RUserDao, RUser> implements RUserService {

    @Override
    public RUser rUserAndRRoleSelectAllInFoByRUserEmail(String email) {
        return this.baseMapper.rUserAndRRoleSelectAllInFoByRUserEmail(email);
    }


    @Override
    public Map<String, Object> SmsVerification(String phone) {
        Map<String, Object> map = new HashMap<>();
        try {
            String s = AliyunConfig.sendSms(phone);
            map.put("code", 200);
            map.put("msg", "短信验证发送成功");
            map.put("data", s);
            return map;
        } catch (ClientException e) {
            map.put("code", 300);
            map.put("msg", e.getMessage());
            return map;
        }
    }

    @Override
    public Integer userInFoInsert(RUser rUser) {
        return this.baseMapper.insert(rUser);
    }

    @Override
    public Integer userInFoUpdate(RUser rUser, UpdateWrapper<RUser> wrapper) {
        return this.baseMapper.update(rUser,wrapper);
    }

    @Override
    public RUser userInFoSelectOne(String email) {
        return this.baseMapper.selectOne(new QueryWrapper<RUser>().select("userid","username","useremail","userphone","userprofile").eq("useremail",email));
    }

}
